<template>
  <div>
      <!-- 添加按钮 -->
      <el-button @click="willAdd" type="primary" class="but">添加</el-button>
      <!-- 表格 -->
      <!-- 绑定自定义事件willUpdate -->
      <!-- arr传给list -->
      <list-vue @willUpdate="willUpdate" :arr="arr" @init="getlist"></list-vue>
      <!-- 弹框 -->
      <!-- 传递info  传递arr-->
      <!-- 绑定自定义事件getlist -->
      <form-vue :info="info" :arr="arr" @init="getlist" ref="form"></form-vue>
  </div>
</template>
<script>
import listVue from "./components/list.vue";
import formVue from "./components/form.vue";
// import { reqmenuadd, reqmenuedit, reqmenuinfo } from "../../../http/api";
import { mapGetters, mapActions } from "vuex";
import { reqmenulist } from '../../http/api';
// import { reqmenulist } from "../../http/api";
export default {
  components:{
      listVue,
      formVue
  },
  props: [],
  data() {
    return {
      //1初始化状态
      info:{
        isshow:false,
        isAdd:true
      },
      //初始化列表数据
      arr:[]
    };
  },
  computed: {
    ...mapGetters({})
  },
  mounted() {
    this.getlist()
  },
  methods: {
    ...mapActions({}),
    //2点击添加
    willAdd(){
      this.info.isshow = true
      this.info.isAdd = true
    },
    //点击编辑
    willUpdate(id){
      this.info.isshow = true
      this.info.isAdd = false
      //让form调用发请求
      this.$refs.form.getOne(id)
    },
    //请求列表
    getlist(){
      reqmenulist({istree:true}).then(res=>{
        if(res.data.code == 200){
            this.arr = res.data.list?res.data.list:[]
        }
      })
    }
  }
};
</script>
<style scoped lang="less">
@import "../../less/index.less";
.but{
    margin: @margin10;
}
</style>